package com.gitee.xmhzzz.component.mqtt.client.message;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * @ClassName RawMessage
 * @Description
 * @Author wzq
 * @Date 2024/1/11 11:30
 * @Version 1.0
 */
public class RawMessage extends CommonMessage<RawMessage> {
    private String messageContent;

    public RawMessage() {
    }

    public static RawMessage of(String sn, Long timestamp, String deviceId, String productId, String messageContent, Map<String, Object> headers, Map<String, Object> data) {
        RawMessage message = new RawMessage();
        message.setDeviceId(deviceId);
        message.setProductId(productId);
        message.setHeaders(headers);
        message.setData(data);
        message.setMessageContent(messageContent);
        if (StringUtils.isNotBlank(sn)) {
            message.setSn(sn);
        }

        if (Objects.nonNull(timestamp)) {
            message.setTimestamp(timestamp);
        }

        return message;
    }



    public static RawMessageBuilder builder() {
        return new RawMessageBuilder();
    }

    public void setMessageContent(String messageContent) {
        this.messageContent = messageContent;
    }

    public String getMessageContent() {
        return this.messageContent;
    }

    public static class RawMessageBuilder {
        private String sn;
        private Long timestamp;
        private String deviceId;
        private String productId;
        private String messageContent;
        private Map<String, Object> headers;
        private Map<String, Object> data;

        RawMessageBuilder() {
        }

        public RawMessageBuilder sn(String sn) {
            this.sn = sn;
            return this;
        }

        public RawMessageBuilder timestamp(Long timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public RawMessageBuilder deviceId(String deviceId) {
            this.deviceId = deviceId;
            return this;
        }

        public RawMessageBuilder productId(String productId) {
            this.productId = productId;
            return this;
        }

        public RawMessageBuilder messageContent(String messageContent) {
            this.messageContent = messageContent;
            return this;
        }

        public RawMessageBuilder headers(Map<String, Object> headers) {
            this.headers = headers;
            return this;
        }

        public RawMessageBuilder data(Map<String, Object> data) {
            this.data = data;
            return this;
        }

        public RawMessage build() {
            return RawMessage.of(this.sn, this.timestamp, this.deviceId, this.productId, this.messageContent, this.headers, this.data);
        }

        @Override
        public String toString() {
            return "UpRawMessageBuilder{" +
                    "sn='" + sn + '\'' +
                    ", timestamp=" + timestamp +
                    ", deviceId='" + deviceId + '\'' +
                    ", productKey='" + productId + '\'' +
                    ", messageContent='" + messageContent + '\'' +
                    ", headers=" + headers +
                    ", data=" + data +
                    '}';
        }
    }
}
